const http = require('http');

http.createServer((req, resp) => {
    //跨域
    let head = {
        'Content-Type': 'text/html',
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Methods': 'GET,POST',
        'Access-Control-Allow-Headers': 'x-requested-with,content-type'
    };

    let url = new URL(req.url, 'http://localhost:8080');
    console.log(url);

    if (url.pathname == '/') {
        resp.writeHead(200, head);
    } else {
        resp.writeHead(404, head);
    }
    resp.end();
}).listen(8080);
